package com.supermap.newMessage.Dao;

import com.supermap.newMessage.entity.NewMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author lxs
 * @Title:最新消息 数据层
 * @Description:
 * @date 2018/3/14  11:31
 */
@Mapper
public interface NewMessageDao {

    @Select("select t6.*,IFNULL(t6.mid_imgurl,t5.img_url) as imgurl from \n" +
            "(select t2.*,t1.username,IFNULL(t3.img_url,t4.img_url) as mid_imgurl from t_user t1 \n" +
            "INNER JOIN t_newmessage t2 on t1.id=t2.userid\n" +
            "LEFT JOIN t_advisoryinfo t3 on t3.id=t2.typeid\n" +
            "LEFT JOIN t_agrinfo t4 on t4.id=t2.typeid) t6\n" +
            "LEFT JOIN t_disaster t5 on t5.id=t6.typeid where  t6.uid=#{uid}")
    List<NewMessage> getNewMessageList(@Param("uid")String uid);

    @Update("update t_newmessage set state =1 where id=#{id}")
    int updateNewMessage(@Param("id")String id);

    @Select("select t6.*,IFNULL(t6.mid_imgurl,t5.img_url) as imgurl from \n" +
            "(select t2.*,t1.username,IFNULL(t3.img_url,t4.img_url) as mid_imgurl from t_user t1 \n" +
            "INNER JOIN t_newmessage t2 on t1.id=t2.userid\n" +
            "LEFT JOIN t_advisoryinfo t3 on t3.id=t2.typeid\n" +
            "LEFT JOIN t_agrinfo t4 on t4.id=t2.typeid) t6\n" +
            "LEFT JOIN t_disaster t5 on t5.id=t6.typeid where  t6.id=#{id}")
    NewMessage getNewMessageById(@Param("id")String id);
}
